<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>输入框获得焦点和失去焦点的事件</title>
    <style>
        #sp1 {
            color: red;
        }
    </style>
</head>
<body>
<!--onfocus: 输入框获得焦点时执行-->
用户名: <input id="in1" name="user" onfocus="inputFocus()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="sp1">请输入</span>

<script>
    function inputFocus() {
        document.getElementById("sp1").innerHTML="正在输入....."
    }
    document.getElementById("in1").onblur = function () {
        document.getElementById("sp1").innerHTML="请输入"
    }
</script>

</body>
</html>